var randomUtils = require("./randomUtils");
var clickUtils = require("./clickUtils");
var pointMap = require("../pointMap/index");
module.exports = {
  open(appName) {
    this.appName = appName;
    var result = app.launchApp(appName);
    if (!result) {
      console.log("打开：", appName, "失败");
    } else {
      console.log("打开：", appName, "成功");
    }
    return result;
  },
  closeRecent() {
    home();
    sleep(randomUtils.getRandom(2.5, 3, 1000));
    recents();
    sleep(randomUtils.getRandom(2.5, 3, 1000));
    var deviceProduct = device.product;
    if (deviceProduct == "cannon" || deviceProduct == "evergo") {
      //note11
      console.log(deviceProduct, "开始关闭应用");
      swipe(
        device.width / 4 + device.width / 8 + device.width / 16,
        device.height / 2,
        device.width / 20,
        device.height / 2,
        200
      );
    } else {
      //12C
      console.log(deviceProduct, "开始滑动");
      swipe(
        device.width / 2,
        device.height / 2,
        device.width / 2,
        device.height / 16,
        randomUtils.getRandom(300, 500)
      );
    }
    sleep(randomUtils.getRandom(1, 1.5, 1000));
    home();
    sleep(randomUtils.getRandom(2.5, 3, 1000));
    console.log("关闭最近应用:", this.appName || "", "成功");
    return true;
  },
  closeAll() {
    home();
    sleep(randomUtils.getRandom(2.5, 3, 1000));
    recents();
    sleep(randomUtils.getRandom(2.5, 3, 1000));
    clickUtils.clickPointMap(pointMap.app.关闭所有应用);
  },
  checkInstalled(appName) {
    return !!app.getPackageName(appName);
  },
};
